package routes

import (
	"fmt"
	"github.com/gogf/gf/frame/g"
	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/gf/os/gtimer"
	"test/internal/api"
	"test/lib/jupiter/app"
	"test/lib/tools/lgs"
	"time"
)

func MiddlewareCORS(r *ghttp.Request) {
	r.Response.CORSDefault()
	r.Middleware.Next()
}

func Init() {
	lgs.PrintErr(app.DB.CreateTable().Error)

	g.Server().Use(MiddlewareCORS)
	g.Server().Group("", func(g *ghttp.RouterGroup) {
		g.GET("/jupiter",api.Jupiter)
	})
	//启动后打开swagger页面
	gtimer.AddOnce(time.Second, func() {
		fmt.Println("提示: 点击打开 http://localhost" + g.Cfg().GetString("server.Address") + "/ 访问文档")
	})

}

